package pers.vic.practice.module.student.service;

import org.springframework.stereotype.Service;
import pers.vic.boot.base.service.BaseService;
import pers.vic.practice.module.student.mapper.SScoreMapper;
import pers.vic.practice.module.student.model.SCourseSelection;
import pers.vic.practice.module.student.model.SScore;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.function.IntFunction;

/**
 * @description:成绩表 Service
 * @author Vic.xu
 * @date: 2022-04-18 11:16
 */
@Service
public class SScoreService extends BaseService<SScoreMapper, SScore>{

    @Resource
    private SCourseSelectionService courseSelectionService;

    @Override
    protected boolean hasAttachment() {
        return false;
    }

    public void recordScore(Integer selectionId, BigDecimal score) {
        int num = mapper.updateBySelectionId(selectionId, score);
        if (num ==0 ) {
            SCourseSelection selection = courseSelectionService.findById(selectionId);
            if (selection == null) {
                return;
            }
            SScore sScore = new SScore();
            sScore.setScore(score);
            sScore.setNumber(selection.getNumber());
            this.insert(sScore);
        }
    }

}
